/**
 * Created by lijing on 2016-06-22.
 */
$.validator.setDefaults({
    submitHandler: function () {
        savePub();
    }
});
$(document).ready(function () {
    validate();
    $("#idSubmit").click(function (e) {
        validator.resetForm();
    });

    $("#jobTypeName").click(function () {
        $("#jobTypeName").cate({
            title: "职位类别",
            url: G_Path.path + "/sys/tag/category",
            param: {"dictCode": "JOBTYPE"},
            liveSearch: false,
            "id": "jobTypeId",
            "name": "jobTypeName"
        });
    });
    $("#channelName").click(function () {
        $("#channelName").cate({
            title: "渠道",
            url: G_Path.path + "/channel/json",
            liveSearch: false,
            "id": "channelId",
            "name": "channelName"
        });
    });
});

function savePub() {
    $.post(G_Path.path + "/job/channel/relate/save", $("#mainForm").serialize(), function (text) {
        var data = $.parseJSON(text);
        if (data.success) {
            if ("view" == status) {
                history.back();
            } else {
                window.close();
            }
        } else {
            showDialogMessage(data.msg);
        }
    });
}


function validate() {
    //设置默认属性
    $("#mainForm").validate({
        rules: {
            jobTypeName: {
                required: true,
                minlength: 1
            },
            channelJobId: {
                required: true,
                minlength: 1
            },
            channelName: {
                required: true,
                minlength: 1
            }
        },
        messages: {
            name: {
                jobTypeName: "请选择职位",
                minlength: ""
            },
            channelJobId: {
                required: "请输入渠道职位",
                minlength: ""
            },
            channelName: {
                required: "请选择渠道",
                minlength: ""
            }
        }
    });
}